<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>工资管理</title>
    <#include "/common/link.ftl">

</head>
<body class="hold-transition skin-black sidebar-mini">
<div class="wrapper">
    <#include "/common/navbar.ftl">

    <#assign currentMenu="salary"/>

    <#include "/common/menu.ftl">
    <div class="content-wrapper">
        <section class="content-header">
            <h1>工资管理</h1>
        </section>
        <section class="content">
            <div class="box">
                <!--高级查询--->
                <form class="form-inline" id="searchForm" action="/salary/list" method="post">
                    <input type="hidden" name="currentPage" id="currentPage" value="1">
                    <div class="form-group">
                        <label for="keyword">关键字:</label>
                        <input type="text" class="form-control" name="keyword" value="${qo.keyword}" placeholder="请输入姓名">
                    </div>
                    <div class="form-group">
                        <label > 发放方式:</label>
                        <select class="form-control" name="sysItems">
                            <option value="">全部</option>
                            <#list systemDictionaryItemService as s>
                                <option value="${s.id}">${s.title}</option>
                            </#list>
                            <#--<option value="1">银行转账</option>
                            <option value="2">支付宝转账</option>
                            <option value="3">微信转账</option>-->
                        </select>
                        <script>
                            $('select[name=sysItems]').val(${qo.sysItems})
                        </script>
                    </div>
                    <div class="form-group">
                        <label>工资范围查询：</label>
                        <input placeholder="请输入最低工资" type="text"  class="form-control "  name="minSalary" value="${(qo.minSalary?c)!}" /> -
                        <input placeholder="请输入最高工资" type="text"  class="form-control "  name="maxSalary" value="${(qo.maxSalary?c)!}" />
                    </div>
                    <button type="submit" class="btn btn-primary"><span class="glyphicon glyphicon-search"></span> 查询</button>
                    <a href="#" class="btn btn-success btn-input" style="margin: 10px">
                        <span class="glyphicon glyphicon-plus"></span> 添加
                    </a>
                </form>
                <!--编写内容-->
                <div class="box-body table-responsive">
                    <table class="table table-hover table-bordered table-striped">
                        <thead>
                        <tr>
                            <th>编号</th>
                            <th>年份</th>
                            <th>月份</th>
                            <th>员工</th>
                            <th>工资</th>
                            <th>发放方式</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <#list pageInfo.list as p>
                            <tr>
                                <td>${p_index+1}</td>
                                <td>${p.year}</td>
                                <td>${p.month}</td>
                                <td>${p.employee.username}</td>
                                <td>${p.money}</td>
                                <td>${p.systemDictionaryItem.title}</td>
                                <td>
                                    <a href="#" class="btn btn-info btn-xs btn-input" data-id='${p.id}' >
                                        <span class="glyphicon glyphicon-pencil"></span> 编辑
                                    </a>
                                </td>
                            </tr>
                        </#list>
                        </tr>
                        </tbody>
                    </table>
                    <#include "/common/page.ftl" >
                </div>
            </div>
        </section>
    </div>
    <#include "/common/footer.ftl" >
</div>




<!-- Modal -->
<div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">新增/编辑</h4>
            </div>
            <form class="form-horizontal" action="/salary/saveOrUpdate" method="post" id="editForm">
                <div class="modal-body">
                    <input type="hidden" name="id" >
                    <div class="form-group" style="margin-top: 10px;">
                        <label for="name" class="col-sm-3 control-label">年份：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="year"
                                   placeholder="请输入年份">
                        </div>
                    </div>
                    <div class="form-group" style="margin-top: 10px;">
                        <label for="sn" class="col-sm-3 control-label">月份：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="month"
                                   placeholder="请输入月份">
                        </div>
                    </div>
                    <div class="form-group" style="margin-top: 10px;">
                        <label for="sn" class="col-sm-3 control-label">员工：</label>
                        <div class="col-sm-6">
                            <select type="text" class="form-control" name="employeeId">
                                <option value="">请选择员工</option>
                                <#list employees as e>
                                    <option value="${e.id}">${e.username}</option>
                                </#list>
                                <#--<option value="1">李四</option>
                                <option value="2">张三</option>
                                <option value="3">王五</option>-->
                            </select>
                        </div>
                    </div>
                    <div class="form-group" style="margin-top: 10px;">
                        <label for="sn" class="col-sm-3 control-label">工资：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="money"
                                   placeholder="请输入工资">
                        </div>
                    </div>
                    <div class="form-group" style="margin-top: 10px;">
                        <label for="sn" class="col-sm-3 control-label">发放方式：</label>
                        <div class="col-sm-6">
                            <select type="text" class="form-control" name="payoutId">
                                <option value="">请选择发放方式</option>
                                <#list systemDictionaryItemService as s>
                                    <option value="${s.id}">${s.title}</option>
                                </#list>
                                <#--<option value="1">银行转账</option>
                                <option value="2">支付宝转账</option>
                                <option value="3">微信转账</option>-->
                            </select>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button type="submit" class="btn btn-primary btn-submit">保存</button>
                </div>
            </form>
        </div>
    </div>
</div>
<script>
    //添加 / 编辑
    $(".btn-input").click(function () {
        let id = $(this).data('id');//拿到要回显的id

            //清空模态框数据
            $("#editForm input").val('')
            $("#editForm select").val('')

        //console.log(jQuery);
        $.post("/salary/findById",{id:id},function (data) {
           // console.log(data);
            if(data){
            $('input[name=id]').val(data.id)
            $('input[name=year]').val(data.year)
            $('input[name=month]').val(data.month)
            $('select[name=employeeId]').val(data.employeeId)
            $('select[name=payoutId]').val(data.payoutId)
            $('input[name=money]').val(data.money)
            }
        })

        $("#editModal").modal('show')
        $("#editForm").ajaxForm(function (data) {
            if (data.success) {
                Swal.fire({
                    //text: data.msg,
                    icon: 'success',
                    confirmButtonColor: '#3085d6',
                    cancelButtonColor: '#d33',
                    confirmButtonText: '保存成功'
                }).then((result) => {
                    window.location.href="/salary/list";
                })
            }
        })
    })
</script>

</body>
</html>
